<!DOCTYPE HTML>
<html>

<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" type="text/css" href="./css/index.css">
<title>Adding Information</title>
</head>

<body id="fondo">
<div id="cuerpo">
<fieldset style="width: 1000px; color: #FFF;";>
<?php
        include 'header.php';


$selected=$_POST['selected'];
$link = mysqli_connect('localhost', 'root', '');

if (mysqli_connect_errno()) {
        echo 'You cannot connect to mysql';
        exit;
}

$sql = "USE web_db";
$resultado = mysqli_query($link,$sql);

switch ($selected) {
    case "country":
        $sql=Sel_Country();
        break;
    case "mecha":
    	$sql=Sel_Mecha();
    	break;
    case "mission":
    	$sql=Sel_Mission();
    	break;
    case "news":
    	$sql=Sel_News();
    	break;
    case "part":
    	$sql=Sel_Part();
    case "staff":
    	$sql=Sel_Staff();
    	break;
    case "country_mission":
    	$sql=Sel_Country_Miss();
    	break;
    case "mech_mission":
    	$sql=Sel_Mech_Miss();
    	break;
    case "mech_part":
    	$sql=Sel_Mech_Part();
    	break;
    case "rank":
    	$sql=Sel_Rank();
    	break;
}

$data = mysqli_query ($link,$sql)or die($mysqli->error);

if($data){
	echo "You added to $selected succesfully";
}

function Sel_Country() {
	$code=$_POST['campo0'];
	$name=$_POST['campo1'];
	$num_inhabit=$_POST['campo2'];


	$query = "INSERT INTO country (code,name,num_inhabit) VALUES ('$code','$name','$num_inhabit')";
	return $query;
}

function Sel_Mecha() {
	$mec=$_POST['campo0'];
	$image=$_POST['campo1'];
	$id=$_POST['campo2'];


	$query = "INSERT INTO mecha (mec_id,image,id) VALUES ('$mec','$image','$id')";
	return $query;
}

function Sel_Mission() {
	$miss_nr=$_POST['campo0'];
	$date=$_POST['campo1'];
	$name=$_POST['campo2'];
	$desc=$_POST['campo3'];
	$stat=$_POST['campo4'];


	$query = "INSERT INTO mission (miss_nr,date,name,description,status) VALUES ('$miss_nr','$date','$name','$desc','$stat')";
	return $query;
}

function Sel_News() {
	$n_nr=$_POST['campo0'];
	$date=$_POST['campo1'];
	$desc=$_POST['campo2'];
	$work=$_POST['campo3'];


	$query = "INSERT INTO news (n_nr,date,description,workstation) VALUES ('$n_nr','$date','$desc','$work')";
	return $query;
}

function Sel_Part() {
	$sn=$_POST['campo0'];
	$kind=$_POST['campo1'];
	$name=$_POST['campo2'];
	$desc=$_POST['campo3'];
	$price=$_POST['campo4'];
	$weight=$_POST['campo5'];
	$energy=$_POST['campo6'];


	$query = "INSERT INTO part (sn,kind,name,description,price,weight,energy) VALUES ('$sn','$kind','$name','$desc','$price','$weight','$energy')";
	return $query;
}

function Sel_Staff() {
	$id=$_POST['campo0'];
	$pwd=$_POST['campo1'];
	$vorname=$_POST['campo2'];
	$name=$_POST['campo3'];
	$birth_date=$_POST['campo4'];
	$admission_date=$_POST['campo5'];
	$gender=$_POST['campo6'];
	$workstation=$_POST['campo7'];
	$location=$_POST['campo8'];
	$salary=$_POST['campo9'];
	$image=$_POST['campo10'];


	$query = "INSERT INTO staff (id,pwd,vorname,name,birth_date,admission_date,gender,workstation,location,salary,image) VALUES ('$id','$pwd','$vorname','$name','$birth_date','$admission_date','$gender','$workstation','$location','$salary','$image')";
	return $query;	
}

function Sel_Mech_Miss() {
	$mec=$_POST['campo0'];
	$miss_nr=$_POST['campo1'];

	$query = "INSERT INTO mech_mission (mec_id,mission_nr) VALUES ('$mec','$miss_nr')";
	return $query;
}

function Sel_Country_Miss() {
	$code=$_POST['campo0'];
	$miss_nr=$_POST['campo1'];

	$query = "INSERT INTO country_mission (code,mission_nr) VALUES ('$code','$miss_nr')";
	return $query;
}

function Sel_Mech_Part() {
	$mec_id=$_POST['campo0'];
	$sn=$_POST['campo1'];

	$query = "INSERT INTO mech_part (mec_id,sn) VALUES ('$mec_id','$sn')";
	return $query;
}

function Sel_Rank() {
	$rank=$_POST['campo0'];
	$name=$_POST['campo1'];

	$query = "INSERT INTO rank (rank_nr,name) VALUES ('$rank','$name')";
}
	header("location:table_data.php");
?>

<p>Would you like to come back?</p>
<a HREF="admin.php"><input type="button" value="Administration"></a>
<form name="table_select" method='POST' action="table_data.php">
	<input type="hidden" name="tabla" value=<?php echo "'$selected'"; ?> />
	<input type="submit" value="Table Data">
</form>
<a HREF="index.php"><input type="button" value="Index"></a>
<?php
	include 'footer.php';
?>

</body>